<?php
class Crawler{
	var $url = null;
	var $limit = 15;

	public function __construct($url, $limit = 15){
		$this->url = $url;
		if(intval($limit) > 0) $this->limit = $limit;
	}
	public function getRemoteContent($url){
		try{
			// create a new cURL resource
			$ch = curl_init();

			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_USERAGENT, ' Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// require to get data from https

			$data = curl_exec($ch);
			curl_close($ch);
			return $data;
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
		return null;
	}
	public function rssExtractor(){
		$gapi = 'https://ajax.googleapis.com/ajax/services/feed/load?v=2.0&output=json&q=';
		try{
			// create a new cURL resource
			$ch = curl_init();

			curl_setopt($ch, CURLOPT_URL, $gapi . urlencode($this->url) . '&num=' . $this->limit);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_USERAGENT, ' Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// require to get data from https

			$data = curl_exec($ch);
			curl_close($ch);
			$objData = json_decode($data, true);
			if(!empty($objData['responseData']['feed']['entries'])){
				return $objData['responseData']['feed']['entries'];
			}
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
		return null;
	}
}